﻿

using Data.Model.SqlServer;
using DataService.Core.ServiceDTO;
using DataService.Main;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnitTest
{
    public class TestDisposable
    {
        public void DoDispose1()
        {
            var db = DataService.DBMangerFactory.CreateProvider(DatabaseType.SqlServer);


           // SqlConnection sqlConnection = new SqlConnection();



            db.ConnectionString = "连接字符串";
            var tables = ModelDAL.FindAllTables(db);
        }
        public void DoDispose2()
        {
            //这里自动释放资源
            var db = DataService.DBMangerFactory.CreateProvider(DatabaseType.SqlServer);
            db.ConnectionString = "连接字符串";
            var dbConn = db.DbConnection;
            dbConn.Dispose();
            //if (dbConn is IDisposable disp2)
            //{
            //    try
            //    {
            //        disp2.Dispose();
            //    }
            //    catch { }
            //}


            dbConn.Open();
        }
        public void DoDispose3()
        {
            using (var db = DataService.DBMangerFactory.CreateProvider(DatabaseType.SqlServer))
            {
                db.ConnectionString = "连接字符串";

            }
        }

        public void DoDispose4()
        {
            using (var db = DataService.DBMangerFactory.CreateProvider(DatabaseType.SqlServer))
            {
                db.ConnectionString = "";
                List<TB_PersonnelInfo> list1 = new List<TB_PersonnelInfo>();
                DAL.Insert(list1,db);
                DAL.BeatchUpdate(list1, db);
                DAL.BeatchInsert(list1, db);
            }
        }

    }
}
